package evostar.dao;

import evostar.model.OrderInfo;
import evostar.model.SeckillOrder;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface OrderDAO {
    @Select("select * from seckill_order where user_id = #{userId} and goods_id = #{goodsId}")
    SeckillOrder getSeckillOrderByUserIdGoodsId(@Param("userId") int userId,
                                                       @Param("goodsId") int goodsId);

    @Insert("insert into order_info(user_id, goods_id, goods_name, goods_count, goods_price, status, create_date) " +
            "value (#{userId},#{goodsId},#{goodsName},#{goodsCount},#{goodsPrice},#{status}," +
            "#{createDate})")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = Integer.class, before = false, statement = "select last_insert_id()")
    int insert(OrderInfo orderInfo);

    @Insert("insert into seckill_order (user_id, goods_id, order_id) values (#{userId}, #{goodsId}, #{orderId})")
    int inserSeckillOrder(SeckillOrder seckillOrder);
}
